<template>
    <div class="container">
        <div class="handle-box">
                <el-form ref="form" :model="form" label-width="90px" class="flex">
                    <el-form-item label="姓名：">
                        <el-input v-model="name" placeholder="请输入姓名" class="handle-input mr10"></el-input>
                    </el-form-item>
                    <el-form-item label="卡号：">
                        <el-input v-model="name" placeholder="请输入卡号" class="handle-input mr10"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号：">
                        <el-input v-model="name" placeholder="请输入手机号" class="handle-input mr10"></el-input>
                    </el-form-item>
                    <el-form-item label="楼号：">
                        <el-input v-model="name" placeholder="请输入楼号" class="handle-input mr10"></el-input>
                    </el-form-item>
                    <el-form-item label="单元号：">
                        <el-input v-model="name" placeholder="请输入单元号" class="handle-input mr10"></el-input>
                    </el-form-item>
                    <el-form-item label="门牌号：">
                        <el-input v-model="name" placeholder="请输入门牌号" class="handle-input mr10"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="日期范围：">
                       <el-date-picker
                            v-model="value1"
                            type="daterange"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
                        </el-date-picker>
                    </el-form-item> -->
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search">搜索</el-button>
                        <el-button type="danger" icon="el-icon-circle-close">清空</el-button>
                        <el-button type="success" icon="el-icon-circle-plus-outline" @click="addlistdatadiglog()">新增</el-button>
                    </el-form-item>
                    
                </el-form>
            </div>
            <el-table
                :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
            >
                <el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
                <!-- <el-table-column prop="name" label="姓名"></el-table-column> -->
                <!-- <el-table-column prop="phone" label="手机号"></el-table-column> -->
                <el-table-column prop="add" label="所属地区"></el-table-column>
                <el-table-column prop="streetname" label="所属街道"></el-table-column>
                <el-table-column prop="community" label="社区"></el-table-column>
                <!-- <el-table-column prop="buildingno" label="楼号"></el-table-column>
                <el-table-column prop="unit" label="单元"></el-table-column>
                <el-table-column prop="housenumber" label="门牌号"></el-table-column> -->
                <!-- <el-table-column v-for="item in integral" label="积分">
                {{item}}
                </el-table-column> -->
                <!-- <el-table-column prop="cardnumber" label="卡号"></el-table-column> -->
                <el-table-column prop="registrationdate" label="注册日期"></el-table-column>
                <el-table-column prop="state" label="状态"></el-table-column>
                <!-- <el-table-column prop="qitaintegral" label="其他收垃圾累计积分"></el-table-column>
                <el-table-column prop="qitascore" label="其他收垃圾消费积分"></el-table-column>
                <el-table-column prop="qitaremaining" label="其他收垃圾剩余积分"></el-table-column> -->
                <!-- <el-table-column label="垃圾分类">
                    <template slot-scope="scope">￥{{scope.row.money}}</template>
                </el-table-column>
                <el-table-column prop="address" label="积分类型"></el-table-column>
                <el-table-column label="状态" align="center">
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'')"
                        >{{scope.row.state}}</el-tag>
                    </template>
                </el-table-column>

                <el-table-column prop="date" label="分数规则(分)"></el-table-column> -->
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index, scope.row)"
                        >编辑</el-button> |
                        <el-button
                            type="text"
                            @click="handleDelete(scope.$index, scope.row)" style="color:red"
                        >删除</el-button> |
                        <el-button
                            type="text"
                            @click="handleEdit(scope.$index, scope.row)" style="color:#2A47BD"
                        >积分管理</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page="currentPage"  
                    :page-size="pageSize"
                    :total="tableData.length"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
               <!-- 编辑弹出框 -->
            <el-dialog v-dialogDrag title="编辑" :visible.sync="editVisible" width="50%">
                <el-form ref="form" :model="form" label-width="70px" class="display">
                    <el-form-item label="ID：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.id"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="姓名：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="手机号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.phone"></el-input>
                    </el-form-item> -->
                    <el-form-item label="所属地区：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.add"></el-input>
                    </el-form-item>
                    <el-form-item label="所属街道：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.community"></el-input>
                    </el-form-item>
                    <el-form-item label="社区" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.community"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="楼号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.buildingno"></el-input>
                    </el-form-item>
                    <el-form-item label="单元：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.unit"></el-input>
                    </el-form-item>
                    <el-form-item label="门牌号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.housenumber"></el-input>
                    </el-form-item>
                    <el-form-item label="卡号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.cardnumber"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="日期范围：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.registrationdate"></el-input>
                    </el-form-item> -->
                    <el-form-item label="状态：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.state"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="editVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </el-dialog>
            <!-- 新增弹出框 -->
            <el-dialog v-dialogDrag title="新增" :visible.sync="addeditVisible" width="50%">
                <el-form ref="form" :model="form" label-width="70px" class="display">
                    <el-form-item label="ID：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.id"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="姓名：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="手机号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.phone"></el-input>
                    </el-form-item> -->
                    <el-form-item label="所属地区：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.add"></el-input>
                    </el-form-item>
                    <el-form-item label="所属街道：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.stereetname"></el-input>
                    </el-form-item>
                    <el-form-item label="社区：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.community"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="楼号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.buildingno"></el-input>
                    </el-form-item>
                    <el-form-item label="单元：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.unit"></el-input>
                    </el-form-item>
                    <el-form-item label="门牌号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.housenumber"></el-input>
                    </el-form-item>
                    <el-form-item label="卡号：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.cardnumber"></el-input>
                    </el-form-item> -->
                    <!-- <el-form-item label="日期范围：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.registrationdate"></el-input>
                    </el-form-item> -->
                    <el-form-item label="状态：" :label-width="labelwidth" class="wid50">
                        <el-input v-model="form.state"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="addeditVisible = false">取 消</el-button>
                    <el-button type="primary" @click="addsaveEdit">确 定</el-button>
                </span>
            </el-dialog>
        </div>
</template>
<script>
import '../../assets/css/common.css'

export default {
    data(){
        return{
              currentPage:1, //初始页
                pagesize:10,    //    每页的数据
                userList: [],
                address:'',
                name:'',
                value1: '',
                labelswidth: '160px',
                labelwidth: '120px',
                form:{
                    integral: '',
                    score: '',
                    remaining: '',
                    chuyuintegral: '',
                    chuyuscore: '',
                    chuyuremaining: '',
                    youhaiintegral:'',
                    youhaiscore: '',
                    youhairemaining: '',
                    qitaintegral: '',
                    qitascore: '',
                    qitaremaining: ''
                },
            tableData: [
                {
                    id: '1',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                },{
                    id: '2',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                },{
                    id: '3',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                },{
                    id: '4',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                },{
                    id: '5',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                },{
                    id: '6',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                },{
                    id: '7',
                    name: '容碧',
                    phone: '18275623942',
                    add: '北京-北京市-西城区',
                    community: '蒂花里社区',
                    streetname:'华天道',
                    buildingno: '7',
                    unit: '1',
                    housenumber: '1906',
                    integral: [5,3,5,6],
                    cardnumber: 'BAA064877',
                    registrationdate: '2019-03-18 11:47:33',
                    state: '正常'
                }
            ],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1,
            addeditVisible:false
        }
    },
    created() {
        // this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        // getData() {
        //     fetchData(this.query).then(res => {
        //         console.log(res);
        //         this.tableData = res.list;
        //         this.pageTotal = res.pageTotal || 50;
        //     });
        // },
        // 触发搜索按钮
        // handleSearch() {
        //     this.$set(this.query, 'pageIndex', 1);
        //     // this.getData();
        // },
        addlistdatadiglog(){
            this.addeditVisible = true
        },
        addsaveEdit(){
            this.addeditVisible =false
        },
         mohu() {
            var search = this.name;
            console.log(search)
            var newdate = [];
            if(search){
                if(search)
                 this.tableData.filter(item=>{
                    if(item.name.indexOf(search) != -1){
                        newdate.push(item)
                    }
                })
            }else if (search == ''){
                console.log(this.tableData)
            }
            this.tableData = newdate
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible = true;
        },
        handleDelete(index, row) {
            // 二次确认删除
            this.$confirm('确定要删除吗？', '提示', {
                type: 'warning'
            })
                .then(() => {
                    this.$message.success('删除成功');
                    this.tableData.splice(index, 1);
                })
                .catch(() => {});
        },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(currentPage) {
            this.currentPage = currentPage;
            console.log(this.currentPage)
            // this.$set(this.query, 'pageIndex', val);
            // this.getData();
        },
        handleSizeChange(size){
            this.pagesize = size;
            console.log(this.pagesize)
        }
    }
}
</script>
<style scoped>

</style>